<?xml version='1.0' encoding='UTF-8' ?>
<!--
  ~ Copyright (c) 2014 Luca Agostini, Alessandro Cantini, Alessandro Dignani
  ~
  ~ This file is part of MeteoCal.
  ~
  ~ MeteoCal is free software: you can redistribute it and/or modify
  ~ it under the terms of the GNU General Public License as published by
  ~ the Free Software Foundation, either version 3 of the License, or
  ~ (at your option) any later version.
  ~
  ~ This program is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ~ GNU General Public License for more details.
  ~
  ~ You should have received a copy of the GNU General Public License
  ~ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:composite="http://java.sun.com/jsf/composite">

<composite:interface>
    <composite:attribute name="showButtons" type="boolean" required="true"/>
    <composite:attribute name="scheduleBean" required="true"
                         type="it.polimi.se2.agostini_cantini_dignani.meteocal.gui.CalendarBean"/>
</composite:interface>

<composite:implementation>

    <p:schedule id="schedule" value="#{cc.attrs.scheduleBean.model}"
                timeZone="#{cc.attrs.scheduleBean.timeZone}"
                allDaySlot="false"
                widgetVar="myschedule"
                timeFormat="#{cc.attrs.scheduleBean.shortTimePattern}"
                locale="en">
        <p:ajax event="eventMove" listener="#{cc.attrs.scheduleBean.onEventMove}"
                update="eventDialog"/>
        <p:ajax event="eventResize" listener="#{cc.attrs.scheduleBean.onEventResize}"
                update="eventDialog"/>
        <p:ajax event="eventSelect" listener="#{cc.attrs.scheduleBean.onEventSelect}"
                update="eventDialog"
                oncomplete="PF('eventDialog').show();"/>
        <p:ajax event="dateSelect" oncomplete="PF('eventDialog').hide();"/>
    </p:schedule>

    <p:dialog id="eventDialog" widgetVar="eventDialog"
              header="${cc.attrs.scheduleBean.selectedEvent.title}"
              showEffect="fade" hideEffect="clip" resizable="false" draggable="false"
              style="background: #fff url(${cc.attrs.scheduleBean.backgroundPath}) no-repeat; background-size: 100%;">

        <h:panelGrid id="eventDetails" columns="2"
                     style="color: ${cc.attrs.scheduleBean.textColor}; ">

            <h:outputText for="from" value="From:"/>
            <h:outputText id="from" value="${cc.attrs.scheduleBean.selectedEvent.startDate}">
                <f:convertDateTime pattern="#{cc.attrs.scheduleBean.dateTimePattern}"
                                   timeZone="#{cc.attrs.scheduleBean.timeZone}"/>
            </h:outputText>

            <h:outputText for="to" value="To:"/>
            <h:outputText id="to" value="${cc.attrs.scheduleBean.selectedEvent.endDate}">
                <f:convertDateTime pattern="#{cc.attrs.scheduleBean.dateTimePattern}"
                                   timeZone="#{cc.attrs.scheduleBean.timeZone}"/>
            </h:outputText>

            <h:outputText for="owner" value="Owner:"/>
            <h:outputText id="owner" value="${cc.attrs.scheduleBean.selectedEvent.owner.email}"/>

            <h:outputText for="description" value="Description:"
                          rendered="${cc.attrs.scheduleBean.selectedEvent.description != null}"/>
            <h:outputText id="description"
                          value="${cc.attrs.scheduleBean.selectedEvent.description}"
                          rendered="${cc.attrs.scheduleBean.selectedEvent.description != null}"/>

            <h:outputText for="place" value="Place:"
                          rendered="${cc.attrs.scheduleBean.selectedEvent.place != null}"/>
            <h:outputText id="place" value="${cc.attrs.scheduleBean.selectedEvent.place}"
                          rendered="${cc.attrs.scheduleBean.selectedEvent.place != null}"/>

            <h:outputText id="public" value="Public"
                          rendered="${cc.attrs.scheduleBean.selectedEvent.public}"/>
            <h:outputText value="" rendered="${cc.attrs.scheduleBean.selectedEvent.public}"/>

            <h:outputText id="outdoor" value="Outdoor"
                          rendered="${cc.attrs.scheduleBean.selectedEvent.outdoor}"/>
            <h:outputText value="" rendered="${cc.attrs.scheduleBean.selectedEvent.outdoor}"/>

            <h:outputText value="Participant users:"
                          rendered="#{!cc.attrs.scheduleBean.selectedEvent.participantCalendars.isEmpty()}"/>
            <h:dataTable id="participantUsers" var="c"
                         value="#{cc.attrs.scheduleBean.selectedEvent.participantCalendars}"
                         rendered="#{!cc.attrs.scheduleBean.selectedEvent.participantCalendars.isEmpty()}">
                <h:column>
                    <h:outputText value="#{c.owner.email}"/>
                </h:column>
            </h:dataTable>

            <h:outputText value="Invited users:"
                          rendered="#{!cc.attrs.scheduleBean.selectedEvent.invitedUsers.isEmpty()}"/>
            <h:dataTable id="invitedUsers" var="u"
                         value="#{cc.attrs.scheduleBean.selectedEvent.invitedUsers}"
                         rendered="#{!cc.attrs.scheduleBean.selectedEvent.invitedUsers.isEmpty()}">
                <h:column>
                    <h:outputText value="#{u.email}"/>
                </h:column>
            </h:dataTable>

            <h:outputText value="Users who have declined:"
                          rendered="#{!cc.attrs.scheduleBean.selectedEvent.usersWhoHaveDeclined.isEmpty()}"/>
            <h:dataTable id="usersWhoHaveDeclined" var="u"
                         value="#{cc.attrs.scheduleBean.selectedEvent.usersWhoHaveDeclined}"
                         rendered="#{!cc.attrs.scheduleBean.selectedEvent.usersWhoHaveDeclined.isEmpty()}">
                <h:column>
                    <h:outputText value="#{u.email}"/>
                </h:column>
            </h:dataTable>

            <h:outputText value="#{cc.attrs.scheduleBean.selectedEvent.weatherForecast.weather}"
                          rendered="#{cc.attrs.scheduleBean.selectedEvent.weatherForecast != null}"/>
            <h:panelGrid columns="2"
                         rendered="#{cc.attrs.scheduleBean.selectedEvent.weatherForecast != null}">
                <p:graphicImage url="${cc.attrs.scheduleBean.iconUrl}"
                                alt="${cc.attrs.scheduleBean.selectedEvent.weatherForecast.weather}"
                                rendered="#{cc.attrs.scheduleBean.selectedEvent.weatherForecast != null}"/>
                <h:outputText value="#{cc.attrs.scheduleBean.temperature}"/>
            </h:panelGrid>


            <p:button value="Edit event"
                      outcome="/user/edit-event"
                      icon="ui-icon-pencil"
                      rendered="#{cc.attrs.showButtons and cc.attrs.scheduleBean.selectedEvent.editable}"
                      onclick="#{editEventBean.setEventId(cc.attrs.scheduleBean.selectedEvent.eventId)}">
            </p:button>
            <h:form>
                <p:commandButton value="Remove participation"
                                 icon="ui-icon-close"
                                 actionListener="#{cc.attrs.scheduleBean.removeParticipation}"
                                 ajax="false"
                                 rendered="#{cc.attrs.showButtons and !cc.attrs.scheduleBean.selectedEvent.editable}"/>
            </h:form>
        </h:panelGrid>

    </p:dialog>

    <p:confirmDialog showEffect="fade" hideEffect="fade"
                     header="Overlapping event detected"
                     message="You have an event scheduled at the same time, do you want to continue?"
                     widgetVar="calendarConfirmDialog"
                     icon="ui-icon-alert">
        <h:form>
            <p:commandButton value="Yes"
                             action="#{cc.attrs.scheduleBean.saveAction}"
                             icon="ui-icon-check"
                             onclick="PF('calendarConfirmDialog').hide()"/>
            <p:commandButton value="No"
                             icon="ui-icon-close"
                             action="#{cc.attrs.scheduleBean.cancelUpdate}"
                             update=":#{cc.attrs.id}:schedule"
                             onclick="PF('calendarConfirmDialog').hide()"/>
        </h:form>
    </p:confirmDialog>

    <script type="text/javascript">
        PrimeFaces.locales['en'] = {
            month: 'Month',
            week: 'Week',
            day: 'Day',
            currentText: 'Today'
        };
    </script>
</composite:implementation>
</html>

